package dungeonPackage;

import java.util.*;

import squareBorderPackage.*;

/**
 * A class of SingularDungeons involving maxCoordinates, squares and a motherDungeon.
 * 
 * @param 	<E>
 * 			The type of squares the dungeon can contain.
 * 
 * @version	1.0
 * @author 	Esther Alberts & Jessa Bekker
 */
public abstract class SingularDungeon<E extends Square> extends Dungeon<E> {

	/**
	 * Initialize a new SingularDungeon with given max coordinates.
	 * 
	 * @effect	This new SingularDungeon is initialized as a dungeon with the given maxCoordinates.
	 * 			|super(maxCoordinates)
	 */
	public SingularDungeon(Orientation maxCoordinates) {
		super(maxCoordinates);
	}
	
	/**
	 * Check whether the x, y and z coordinates are equal in one of the subDungeons of the rootDungeon or in
	 * the rootDungeon itself.
	 */
	protected boolean sameCoordinates(Orientation orientation){
		if(orientation.getX() == orientation.getY()
				&& orientation.getX() == orientation.getZ())
			return true;
		return false;
	}
	
	/**
	 * Return an iterator returning all the squares in this singular
	 * dungeon one by one.
	 */
	@Override
	public Iterator<E> iterator() {
		return new Iterator<E>() {

			@Override
			public boolean hasNext() {
				return squareIterator.hasNext();
			}

			@Override
			public E next() throws NoSuchElementException {
				if (!hasNext())
					throw new NoSuchElementException();
				return squareIterator.next();
					
			}

			@Override
			public void remove() throws UnsupportedOperationException {
				throw new UnsupportedOperationException();
			}
			
			private Iterator<E> squareIterator = getSquares().values().iterator();

			
		};
	}

}
